import turtle as t
import random


# 设置坐标范围
min_x, max_x = -300, 300
min_y, max_y = -300, 300


# 在坐标(x,y)处画一个直径为diameter 颜色为ccolor_code的气球
def draw_balloon(turtle, x, y, diameter, color_code):
    turtle.hideturtle()
    turtle.penup()
    turtle.goto(x, y)
    turtle.dot(diameter, color_code)
    turtle.goto(x, y-diameter/2)
    turtle.pencolor(color_code)
    turtle.right(90)
    turtle.pendown()
    turtle.forward(diameter)
    turtle.left(90)


# 生成随机坐标点的函数
def generate_random_coordinate(min_value, max_value):
    return random.uniform(min_value, max_value)


# 生成随机点的函数
def generate_random_point(min_x, max_x, min_y, max_y):
    return generate_random_coordinate(min_x, max_x), generate_random_coordinate(min_y, max_y)


# 生成随机颜色的函数
def generate_random_color_code():
    # 生成随机的红色、绿色、蓝色值
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)

    # 格式化为颜色代码字符串
    color_code = f"#{r:02x}{g:02x}{b:02x}"
    return color_code


t.title("画气球")

screen = t.Screen()
screen.bgcolor(0.9, 0.9, 1)

t.speed(100)
for i in range(5):
    # 生成一个随机点
    random_point = generate_random_point(min_x, max_x, min_y, max_y)
    # 生成随机颜色
    color = generate_random_color_code()
    draw_balloon(t, random_point[0], random_point[1], 100, color)

t.done()
